<template>
	<view class="content">
		<u-navbar bgColor="transparent" titleStyle="color:#fff" title="修改支付密码" leftIconColor="#fff" :autoBack="true"
			:placeholder="false">
		</u-navbar>
		<view style="height: 70rpx;"></view>
		<view class="content-box">
			<view class="entry">
				<view class="content-title">
					手机号
				</view>
				<u--input type="number" maxlength="16" border="none" color="#fff" v-model="tell" placeholder="请输入您的手机号">
					<template slot="suffix">
						<u-code ref="uCode" @change="codeChange" seconds="60" changeText="X秒重新获取"></u-code>
						<text @tap="getCode" style="color:  #98F083;">{{tips}}</text>
					</template>
				</u--input>
			</view>
			<view class="entry">
				<view class="content-title">
					验证码
				</view>
				<u--input type="number" maxlength="16" border="none" color="#fff" v-model="code"
					placeholder="请输入您的验证码"></u--input>
			</view>
			<view class="entry">
				<view class="content-title">
					新支付密码
				</view>
				<u--input type="number" :type="pass_type" maxlength="6" border="none" color="#fff" v-model="neWpassword"
					placeholder="请输入您的新支付密码">
					<template slot="suffix">
						<u-icon v-if="pass_type == 'password'" name="eye-fill" color="#fff" size="18"
							@click="changeType"></u-icon>
						<u-icon v-else name="eye-off" color="#fff" size="18" @click="changeType"></u-icon>
					</template>
				</u--input>
			</view>
			<view class="entry">
				<view class="content-title">
					确认新支付密码
				</view>
				<u--input maxlength="6" :type="neWpass_type" border="none" color="#fff" v-model="password"
					placeholder="请再次输入您的新支付密码">
					<template slot="suffix">
						<u-icon v-if="neWpass_type == 'password'" name="eye-fill" color="#fff" size="18"
							@click="modifyType"></u-icon>
						<u-icon v-else name="eye-off" color="#fff" size="18" @click="modifyType"></u-icon>
					</template>
				</u--input>
			</view>
			<view class="tips">
				仅支持数字，只能6位，不能使用空格
			</view>
			<view class="btn" @click="goRevise">
				<u-button size="large" class="btn-color"
					color="linear-gradient( 90deg, #C8F673 0%, #98F083 100%)"
					type="primary" text="确认" shape="circle"></u-button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				neWpassword: '',
				pass_type: 'password',
				neWpass_type: 'password',
				password: '',
				tips: '',
				tell: '',
				code: ''
			}
		},
		onLoad() {},
		watch: {
			value(newValue, oldValue) {
				// console.log('v-model', newValue);
			}
		},
		methods: {
			changeType() {
				if (this.pass_type == 'password') {
					this.pass_type = 'text'
				} else {
					this.pass_type = 'password'
				}
			},
			modifyType() {
				if (this.neWpass_type == 'password') {
					this.neWpass_type = 'text'
				} else {
					this.neWpass_type = 'password'
				}
			},
			codeChange(text) {
				this.tips = text;
			},
			getCode() {
				if (this.tell == '') {
					uni.showToast({
						title: '请输入您的手机号！',
						icon: 'none'
					})
					return
				}
				if (this.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					uni.showLoading({
						title: '正在获取验证码'
					})
					let params = {
						phone: this.tell,
					}
					this.$Request({
						method: 'POST',
						url: '/api/login/sendRegister',
						data: params
					}).then(res => {
						if (res.code == 1) {
							uni.hideLoading();
							// 这里此提示会被this.start()方法中的提示覆盖
							uni.$u.toast('验证码已发送');
							// 通知验证码组件内部开始倒计时
							this.$refs.uCode.start();
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none'
							})
						}
					})
				} else {
					uni.$u.toast('倒计时结束后再发送');
				}
			},
			change(e) {
				console.log('change', e);
			},
			goRevise() {
				if (this.tell == '') {
					uni.showToast({
						title: '请输入您的手机号！',
						icon: 'none'
					})
					return
				}
				if (this.code == '') {
					uni.showToast({
						title: '请输入您的验证码！',
						icon: 'none'
					})
					return
				}
				if (this.neWpassword == '') {
					uni.showToast({
						title: '请输入您的新支付密码！',
						icon: 'none'
					})
					return
				}

				if (this.password == '') {
					uni.showToast({
						title: '请再次输入您的新支付密码！',
						icon: 'none'
					})
					return
				}
				if (this.password != this.neWpassword) {
					uni.showToast({
						title: '两次支付密码不一致！',
						icon: 'none'
					})
					return
				}
				const regex = /^[1-9]\d*$/;
				if (regex.test(this.password) == false) {
					uni.showToast({
						title: '支付密码只能为纯数字！',
						icon: 'none'
					})
					return
				}

				let params = {
					mobile: this.tell,
					password: this.password,
					code: this.code
				}
				this.$Request({
					method: 'POST',
					url: '/api/personal/changePayPass',
					data: params
				}).then(res => {
					if (res.code == 1) {
						this.code = ''
						this.neWpassword = ''
						this.password = ''
						this.tell = ''
						uni.showToast({
							title: '修改成功',
							icon: 'none'
						})
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
			}
		}
	}
</script>
<style>
	page {
		background-color: #17191A;
	}
	.btn-color {
		color: #17191A !important;
	}
</style>
<style lang="scss" scoped>
	.content {
		background-image: url('../../../static/my/my-bg.png');
		background-repeat: no-repeat;
		background-size: 100% 558rpx;

		.content-box {
			padding: 30rpx;
			color: #fff;

			.entry {
				padding: 30rpx;
				background-color: rgba(238, 238, 238, 0.2);
				border-radius: 40rpx;
				font-size: 28rpx;
				display: flex;
				justify-content: space-between;
				margin-top: 30rpx;

				.content-title {
					width: 200rpx;
					font-size: 28rpx;
					font-weight: 600;
				}
			}

			.btn {
				padding: 30rpx;
				margin-top: 30rpx;
			}
			.tips {
				margin-top: 30rpx;
			}
		}
	}
</style>